package cn.sinata.xldutils_kotlin

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.support.v4.app.Fragment
import android.util.Log
import io.reactivex.Flowable
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * 打印公司日志
 */
fun Any.sysErr(msg:Any?){
    Log.e("sinata","--------"+msg)
}

fun <T> Flowable<T>.ioScheduler(): Flowable<T> = this.subscribeOn(Schedulers.io())
fun <T> Flowable<T>.defaultScheduler(): Flowable<T> = this.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
fun <T> Observable<T>.defaultScheduler(): Observable<T> = this.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())

fun Activity.callPhone(phone:String?){
//    val isAllow = permission(Manifest.permission.CALL_PHONE,"拨号权限",15)
//    if (isAllow) {
//
//    } else {
//        toast("没有拨号权限")
//    }
    val p = phone ?: ""
    val intent = Intent(Intent.ACTION_DIAL)
    intent.data = Uri.parse("tel:" + p)
    this.startActivity(intent)
}

fun Fragment.callPhone(phone:String?){
    activity.callPhone(phone)
}